package com.gidas.server;

import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.gidas.client.ObjectSerializable;
import com.google.appengine.api.datastore.Text;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class ObjectDB {
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;
	
	
	
	@Persistent
	private String name;
	
	@Persistent
	private String address;
	
	@Persistent
	private Double lat;

	@Persistent
	private Double lng;
		
	@Persistent
	private String objectType;
	
	@Persistent
	private int takesTimeMinutes;

	//TODO automatizuoti avg skaiciavima
	@Persistent
	private int takesTimeMinutesUsersAvg;
	@Persistent
	private int ratingUsersAvg;
	
	@Persistent
	private int rating;

	//TODO 
	//padaryti kad administratorius galetu prideti savo reitinga, 
	//kuris skaiciuotusi i bendra reitinga ar butu atskirai vaizduojams kaip
	//editors rating ar kzkas...

/*	
	@Persistent
	private int priority;
*/

	@Persistent
	private String author;
	
	@Persistent
	private Date creation;
	
	@Persistent
	private Date modified;
	
	@Persistent
	private Text description;
	
	@Persistent
	private Boolean confirmed;
	
	@Persistent(mappedBy = "POI")
    private List<ObjectEvaluationDB> objectEvaluationSets;
	
	
	
	
	// TODO
	// Comments
	// Ratings
	// pagalvoti kaip skaiciuoti reitingus, kaip paimt vidurki
	// busena: patvirtintas, nepatvirtintas, privatus
	// audio failas (????)
	
	public ObjectDB()
	{
		
	}
	public ObjectDB(ObjectSerializable object)
	{
		this.setName(object.getName());
		this.setAddress(object.getAddress());
		this.setLat(object.getLat());
		this.setLng(object.getLng());
		this.setObjectType(object.getObjectTypey());
		this.setTakesTimeMinutes(object.getTakesTimeMinutes());
		this.setRating(object.getRating());
		this.setAuthor(object.getAuthor());
		this.setCreation(object.getCreation());
		this.setDescription(object.getDescription());
		this.setConfirmed(object.getConfirmed());
		
	}
	
	public ObjectSerializable getObjectSerializable()
	{
		ObjectSerializable object = new ObjectSerializable();

		object.setName(name);
		object.setAddress(address);
		object.setLat(lat);
		object.setLng(lng);
		object.setObjectType(objectType);
		object.setTakesTimeMinutes(takesTimeMinutes);
		object.setRating(rating);
		object.setAuthor(author);
		object.setCreation(creation);
		object.setDescription(description.getValue());
		object.setConfirmed(confirmed);
				
		return object;
		
	}
	public Long getId() 
	{
		return id;
    }

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getAddress() {
		return address;
	}

	public void setTakesTimeMinutes(int takesTimeMinutes) {
		this.takesTimeMinutes = takesTimeMinutes;
	}

	public int getTakesTimeMinutes() {
		return takesTimeMinutes;
	}

	public void setLat(Double lat) {
		this.lat = lat;
	}

	public Double getLat() {
		return lat;
	}

	public void setLng(Double lng) {
		this.lng = lng;
	}

	public Double getLng() {
		return lng;
	}

	public void setObjectType(String objectType) {
		this.objectType = objectType;
	}

	public String getObjectTypey() {
		return objectType;
	}
/*
	public void setPriority(int priority) {
		this.priority = priority;
	}

	public int getPriority() {
		return priority;
	}
*/
	public void setAuthor(String author) {
		this.author = author;
	}

	public String getAuthor() {
		return author;
	}

	public void setDescription(String description) {
		Text tmpText = new Text(description);
		this.description = tmpText;
	}

	public Text getDescription() {
		return description;
	}

	public void setRating(int rating) {
		this.rating = rating;
	}

	public int getRating() {
		return rating;
	}

	public void setCreation(Date creation) {
		this.creation = creation;
	}

	public Date getCreation() {
		return creation;
	}

	public void setModified(Date modified) {
		this.modified = modified;
	}

	public Date getModified() {
		return modified;
	}

	public void setContactInfoSets(List<ObjectEvaluationDB> objectEvaluationSets) {
		this.objectEvaluationSets = objectEvaluationSets;
	}

	public List<ObjectEvaluationDB> getContactInfoSets() {
		return objectEvaluationSets;
	}

	public void setConfirmed(Boolean confirmed) {
		this.confirmed = confirmed;
	}

	public Boolean getConfirmed() {
		return confirmed;
	}
	public void setTakesTimeMinutesUsersAvg(int takesTimeMinutesUsersAvg) {
		this.takesTimeMinutesUsersAvg = takesTimeMinutesUsersAvg;
	}
	public int getTakesTimeMinutesUsersAvg() {
		return takesTimeMinutesUsersAvg;
	}
	public void setRatingUsersAvg(int ratingUsersAvg) {
		this.ratingUsersAvg = ratingUsersAvg;
	}
	public int getRatingUsersAvg() {
		return ratingUsersAvg;
	}
}
